package adke.models.powerups;

import adke.Util;
import adke.managers.GameManager;
import adke.managers.ImageManager;
import adke.models.Player;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.security.acl.Owner;

// powerups die een graphic willen moeten getGraphic overriden

public abstract class Powerup
{
    public final static int IMG_DIMENSION = 40;
    
    // plaats op het veld
    private int x, y;
    
    // niet private: moet beschikbaar zijn
    protected Player owner;
    
    private Image graphic;
    
    public Powerup(Player owner)
    {
        this.owner = owner;
        x = -1; y = -1;
    }
    
    public Powerup()
    {
        x = -1; y = -1;
    }
    
    public void setOwner(Player newOwner)
    {
        owner = newOwner;
    }
    
    public Player getOwner()
    {
        return owner;
    }
    
    public String toString()
    {
        return this.getClass().getSimpleName();
    }
    
    public Image getGraphic()
    {
        // kijk eerst of we het een verrassing moeten houden of niet
        if (GameManager.getPowerupForeseeableFX())
        {
            // kijk of het plaatje bestaat
            if (ImageManager.imageAvailable(this))
            {
                if (graphic == null) graphic = ImageManager.getImage(this);
            }
            
            // plaatje niet available
            else
            {
                if (graphic == null) graphic = ImageManager.getEmptyImage();
            }
        }
        else
        {
            if (graphic == null) graphic = ImageManager.getImage("UnknownPowerup");
        }
        
        return graphic;
    }
    
    public void setLocation(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    
    public int getX()
    {
        return x;
    }
    
    public int getY()
    {
        return y;
    }
    
    public boolean isOnLocation(int lineX, int lineY)
    {
        Rectangle r = getLocation();
        return r.contains(lineX, lineY);
    }
    
    public Rectangle getLocation()
    {
        return new Rectangle(x, y, IMG_DIMENSION, IMG_DIMENSION);
    }
}
